#ifndef __LCD_DRV_H
#define __LCD_DRV_H

#include "_config_cpu_.h"
#include "_config_cpu_display.h"
#include "delay.h"

#if (LCD_CONNECTION == LCD_CONNECTION_PCF8574)
	#include "_config_cpu_i2c.h"
	#if (PCF8574_USE_I2C == 0)
		#include "i2c0.h"
		#define lcd_Send  		i2c0_WriteBuffer
		#define lcd_Receive  	i2c0_ReadBuffer
	#elif (PCF8574_USE_I2C == 1)
		#include "i2c1.h"
		#define lcd_Send 		i2c1_WriteBuffer
		#define lcd_Receive 	i2c1_ReadBuffer
	#elif (PCF8574_USE_I2C == 2)
		#include "i2c2.h"
		#define lcd_Send 		i2c2_WriteBuffer
		#define lcd_Receive 	i2c2_ReadBuffer
	#else
		#error NÃO FOI DEFINIDO QUAL O BARRAMENTO I2C NO _config_cpu_display.h
	#endif

	void lcd_write(u8 value, u8 rs, u8 dualAccess);
	#define lcd_write_init(value)		lcd_write(value, 0, pdFALSE)
	#define lcd_write_command(value)	lcd_write(value, 0, pdTRUE)
	#define lcd_write_data(value)		lcd_write(value, 1, pdTRUE)

	u8 lcd_read(u8 rs);
	#define lcd_read_command()		lcd_read(0)
	#define lcd_read_data()			lcd_read(1)
#elif (LCD_CONNECTION == LCD_CONNECTION_GPIO_4BITS)
	void lcd_write(u8 value, u8 rs, u8 dualAccess);
	#define lcd_write_init(value)		lcd_write(value, 0, pdFALSE)
	#define lcd_write_command(value)	lcd_write(value, 0, pdTRUE)
	#define lcd_write_data(value)		lcd_write(value, 1, pdTRUE)

	u8 lcd_read(u8 rs);
	#define lcd_read_command()		lcd_read(0)
	#define lcd_read_data()			lcd_read(1)	
	
	void lcd_config_ports(void);
#elif (LCD_CONNECTION == LCD_CONNECTION_GPIO_8BITS)
	void lcd_write(u8 value, u8 rs);
	#define lcd_write_init(value)		lcd_write(value, 0)
	#define lcd_write_command(value)	lcd_write(value, 0)
	#define lcd_write_data(value)		lcd_write(value, 1)

	u8 lcd_read(u8 rs);
	#define lcd_read_command()		lcd_read(0)
	#define lcd_read_data()			lcd_read(1)

	void lcd_config_ports(void);
#elif (LCD_CONNECTION == LCD_CONNECTION_IOMAP)
	// ACESSO DIRETO IOMAP RAM
	static volatile u8
		*reg1 = (u8 *) LCD_ADDR_CMD, 	// read status and write command
		*reg2 = (u8 *) LCD_ADDR_DATA; 	// read last address data and write data
#else
	#error NÃO FOI DEFINIDO O TIPO DE CONEXÃO DO LCD no config_cpu_display.h
#endif                       
	
#endif
